def maxxes(c):
    if c == 1: return False
    g = True
    v = c-1
    while v >1:
        if not c % v:
            g = False
            break
        v -= 1
    return g

r = list()
s = input()
for i in range(len(s)):
    for v in range(i + 1, len(s) + 1):
        c = int(s[i:v])
        if maxxes(c):
            r += [c]
print(max(r) if r else 0)
